package com.heba.gcglobal

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() {
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
        channel = MethodChannel(
                flutterEngine.dartExecutor.binaryMessenger,
                CHANNEL
        )
    }
    private lateinit var channel: MethodChannel
    private val CHANNEL = "gcglobal"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)


        provideFlutterEngine(this)?.let { GeneratedPluginRegistrant.registerWith(it) }
        channel.setMethodCallHandler(MethodChannel.MethodCallHandler { call, result ->
            if(call.method.equals("ShareWeb")){
                val shareIntent = Intent(Intent.ACTION_VIEW,Uri.parse(call.argument<String>("image")))
                shareIntent.type = "*/*"

                shareIntent.putExtra(Intent.EXTRA_SUBJECT,call.argument<String>("title"));//添加分享内容标题

                shareIntent.putExtra(Intent.EXTRA_TEXT, call.argument<String>("title")+ " " + call.argument<String>("link")) //添加分享内容

                startActivity(Intent.createChooser(shareIntent,"分享"))

            }
        })


    }
}